package com.xzp.bams.client;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @TODO
 * @Author xu
 * 2025/3/22
 */
public class MainPanel extends JPanel {
    private ATMClient atm;

    public  MainPanel(ATMClient atm) {
        this.atm = atm;
        initComponents();
    }

    private void login(ActionEvent e) {
        CardLayout cardLayout = (CardLayout)this.getParent().getLayout();
        //指定跳转至登录界面
        cardLayout.show(this.getParent() , "loginPanel");


        System.out.println(atm.bank);
//        atm.account
    }

    private void register(ActionEvent e) {

        CardLayout cardLayout = (CardLayout)this.getParent().getLayout();
        //指定跳转至注册界面
        cardLayout.show(this.getParent() , "rgisterPanel");

    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        titlelabel1 = new JLabel();
        button1 = new JButton();
        button2 = new JButton();

        //======== this ========
        setLayout(null);

        //---- titlelabel1 ----
        titlelabel1.setText("  \u6a21\u62df       ATM     ICBC      \u7ec8\u7aef");
        add(titlelabel1);
        titlelabel1.setBounds(75, 55, 270, titlelabel1.getPreferredSize().height);

        //---- button1 ----
        button1.setText("\u6ce8\u518c");
        button1.addActionListener(e -> register(e));
        add(button1);
        button1.setBounds(new Rectangle(new Point(65, 155), button1.getPreferredSize()));

        //---- button2 ----
        button2.setText("\u767b\u5f55");
        button2.addActionListener(e -> login(e));
        add(button2);
        button2.setBounds(215, 155, 80, 30);

        setPreferredSize(new Dimension(400, 300));
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JLabel titlelabel1;
    private JButton button1;
    private JButton button2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
